<?php

namespace App\Admin\Controllers;

use App\Models\Match;
use Encore\Admin\Controllers\AdminController;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Show;

class MatchController extends AdminController
{
    /**
     * Title for current resource.
     *
     * @var string
     */
    protected $title = 'Match';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new Match());

        $grid->column('id', trans('admin.Id'));
        $grid->column('name', trans('admin.Name'));
        $grid->column('sport_id', trans('admin.Sport'));
        $grid->column('group_id', trans('admin.Group'));
        $grid->column('level_id', trans('admin.Level'));
        $grid->column('limit', trans('admin.Limit'));
        $grid->column('addr', trans('admin.Addr'));
        $grid->column('addr_lat', trans('admin.Addr lat'));
        $grid->column('addr_lng', trans('admin.Addr lng'));
        $grid->column('begin_time', trans('admin.Begin time'));
        $grid->column('end_time', trans('admin.End time'));
        $grid->column('status', trans('admin.Status'));
        $grid->column('type', trans('admin.Type'));

        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(Match::findOrFail($id));

        $show->field('id', trans('admin.Id'));
        $show->field('name', trans('admin.Name'));
        $show->field('sport_id', trans('admin.Sport'));
        $show->field('group_id', trans('admin.Group'));
        $show->field('level_id', trans('admin.Level'));
        $show->field('limit', trans('admin.Limit'));
        $show->field('addr', trans('admin.Addr'));
        $show->field('addr_lat', trans('admin.Addr lat'));
        $show->field('addr_lng', trans('admin.Addr lng'));
        $show->field('begin_time', trans('admin.Begin time'));
        $show->field('end_time', trans('admin.End time'));
        $show->field('status', trans('admin.Status'));
        $show->field('type', trans('admin.Type'));

        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new Match());

        $form->text('name', trans('admin.Name'));
        $form->select('sport_id', trans('admin.Sport'))->options('/admin/api/sport_types');
        $form->select('group_id', trans('admin.Group'))->options('/admin/api/group');
        $form->select('level_id', trans('admin.Level'))->options('/admin/api/level');
        $form->number('limit', trans('admin.Limit'));
        $form->text('addr', trans('admin.Addr'));
        $form->text('addr_lat', trans('admin.Addr lat'));
        $form->text('addr_lng', trans('admin.Addr lng'));
        $form->datetime('begin_time', trans('admin.Begin time'))->default(date('Y-m-d H:i:s'));
        $form->datetime('end_time', trans('admin.End time'))->default(date('Y-m-d H:i:s'));

        return $form;
    }
}
